<template>
    <div class="con">
        <img src="../assets/images/logo.png" alt="" class="logo" onclick="return false">
        <img src="../assets/images/result.png" alt="" onclick="return false"> 
        <img src="../assets/images/success.png" alt="" class="result" onclick="return false">     
        <img src="../assets/images/btn_CashTicket2.png" alt="" class="btn"  @click.prevent="scan()"> 
       
    </div>
</template>

<script>
export default {
    name: "resultError",
    data() {
        return {
            msg: "Welcome to Your Vue.js App"
        };
    },
    beforeCreate() {
        document.getElementsByTagName("body")[0].className = "bg_MyPoints";
    },
     methods:{
       scan(){
           wx.scanQRCode({
            desc: 'scanQRCode desc',
            needResult: 1, // 默认为0，扫描结果由微信处理，1则直接返回扫描结果，
            scanType: ["qrCode","barCode"], // 可以指定扫二维码还是一维码，默认二者都有
            success: (res=>{
                var result=res.resultStr;  
                var qs=require("qs");
                this.axios({
                    method: "post",
                    url: `${this.siteUrl}/piaowu/api/check_order_online`,
                    data: qs.stringify({
                            member_id: $.cookie("osc_member_id"),
                            token: $.cookie("osc_member_token"),
                            staff_id:  localStorage.getItem('staff_id'),
                            staff_token: localStorage.getItem('staff_token'),
                            code: result
                        })
                })
                .then(response => {
                    // alert(JSON.stringify(response))
                    if (response.data.status == 1) {  
                        this.$router.push({ name: "resultSuccess"});                                     
                    } else {
                        alert("请求失败："+response.data.msg);
                        this.$router.push({ name: "resultError"});

                    }
                })
                .catch(function(error) {
                    console.log(error);
                });                        
            }),
            error: function(res){
                if(res.errMsg.indexOf('function_not_exist') > 0){
                    alert('版本过低请升级')
              }
            }
        });
       }
    },
    mounted: function() {
            var qs=require("qs");
            this.axios({
            method: "post",
            url: `${this.siteUrl}/piaowu/api/get_js_sign`,
            data: qs.stringify({
                url: location.host + location.pathname
            })
            })
            .then(response => {
                console.log(response);
                wx.config({
                debug: false,
                appId: response.data.data.appId,
                timestamp: response.data.data.timestamp,
                nonceStr: response.data.data.nonceStr,
                signature: response.data.data.signature,
                jsApiList: ["scanQRCode"]
                });
            })
            .catch(err => {
                console.log(err);
            });
    }
};
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
.con {
    text-align: center;
    position: relative;
}
.con img {
    width: 100%;
}
.con .logo{
    width: 34%;
    position: absolute;
    left: 50%;
    transform: translate(-50%,30%);

}

.con .result{
    width: 60%;
    margin-top: 50px;
}
.con .btn{
    width: 50%;
}
.con .btnAgain{
    width: 36%;
    margin-top: 20px;
}
</style>
